<script setup>
import { FILE_STATUS } from '@/api/file';
import FileCard from './FileCard.vue'; // 确保路径正确

const props = defineProps({
  files: {
    type: Array,
    required: true,
    default: () => [],
    validator: (list) => {
      return list.every(item => 
        typeof item.file_name === 'string' && 
        Object.values(FILE_STATUS).includes(item.status)
      )
    }
  }
});

defineEmits(['delete-file']);
</script>

<template>
  <div class="file-card-list">
    <div 
      v-if="files.length === 0"
      class="empty-placeholder"
    >
      <el-empty description="暂无文件" />
    </div>
    
    <el-scrollbar v-else>
      <div
        class="card-grid"
      >
        <FileCard
          v-for="file in files"
          :key="file.id"
          :fileName="file.file_name"
          :status="file.status"
          :parseStatus="file.parse_status"
          @delete="$emit('delete-file', file.id)"
          class="grid-item"
        />
      </div>
    </el-scrollbar>
  </div>
</template>

<style scoped>
.file-card-list {
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 8px;
  box-sizing: border-box;
}

.empty-placeholder {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  background-color: var(--el-bg-color);
  border-radius: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  /* height: 100%; */
  height: fit-content;
  overflow-y: auto;
  padding: 8px;
  box-sizing: border-box;
}

/* 响应式布局 - 根据不同屏幕宽度调整列数 */
@media (max-width: 1200px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

.grid-item {
  transition: all 0.3s ease;
  min-width: 0; /* 防止内容溢出 */
}

.grid-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}
</style>